
const box = document.querySelector('.box')
const paramsBox = document.querySelector('.params')


const goodsId = window.sessionStorage.getItem('goodsId')
 !goodsId ? window.location.href = '../views/list2.html' : getGoodsInfo()


 async function getGoodsInfo() {

  const res = await pAjax({
    url: 'http://localhost:8888/goods/item',
    data: { id: goodsId },
    dataType: 'json'
  })

 
  if (res.code === 2) {
    window.location.href = '../views/list2.html'
    return
  }

  console.log(res.info)


  box.innerHTML = `
    <div class="left">
      <img src="${ res.info.img_big_logo }" alt="">
    </div>

    <div class="mask"></div>
   
    <div class="enlarge">
      <img src="${ res.info.img_big_logo }" alt="">
    </div>
    
    <div class="right">
    
      <p class="title">
        ${ res.info.title }
      </p>
      <p class="price">
        <span class="current">￥${ res.info.current_price }</span>
        <span class="old">￥${ res.info.price }</span>
      </p>
      <p class="number">
        <button>-</button>
        <input type="text" value="1">
        <button>+</button>
      </p>
      <p class="btns">
        <button>加入购物车</button>
        <button>立即购买</button>
      </p>
    </div>
  `


 
  paramsBox.innerHTML = res.info.goods_introduce
}
